import {Component, EventEmitter,ViewChild, Input, OnInit, Output} from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
import {HttpClient} from '@angular/common/http';
import { InitService } from '../../../public/serve/init/init.service';
import { appThemeTagUrl } from '../theme-tag.url';
import { themeTag } from '../theme-tag.data';
import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
import { Service } from '../../../server/server';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import {MessageService} from 'primeng/api';

@Component({
  selector: 'app-theme-tag-delete',
  templateUrl: './theme-tag-delete.component.html',
  styleUrls: ['./theme-tag-delete.component.css']
})
export class ThemeTagDeleteComponent implements OnInit {

  @Output() delete = new EventEmitter<void>();

  constructor(
    private server:Service,
    public removeTableService: RemoveTableService,
    private hintsService: HintsService,
    private activatedRoute: ActivatedRoute,
  ) { }

  ngOnInit() {
    this.activatedRoute.url.subscribe(r => {
      this.removeTableService._clearId("labelId");
    })
  }

  _detailsId(id:any){
    this.removeTableService.getRemoveTableId = [];
    this.removeTableService.keywordRemoveChose(true, id, 1)['bool'];
  }

  /**
   * 删除
   */
  _delete(){

    this.removeTableService
    .confirmRemove('ids',this.server.baseUrl +appThemeTagUrl.deleteThemeWordsLabel,'token',themeTag.retrieval.token)
    .then(res => {
      if(res.result_code == '0000'){
        this.delete.emit();
      }
      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err => {
      this.hintsService.messages('error','error');
      return;
    });
  }

}
